package com.lhy.skywalking.product.factory;

import com.lhy.skywalking.common.domain.AjaxResult;
import com.lhy.skywalking.product.ProductFeignService;
import com.lhy.skywalking.product.dto.ProductDTO;
import feign.FeignException;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

@Component
public class ProductFallbackFactory implements FallbackFactory<ProductFeignService> {
    @Override
    public ProductFeignService create(Throwable throwable) {
        return new ProductFeignService() {
            @Override
            public AjaxResult findById(Long id) {
                if (throwable instanceof FeignException.ServiceUnavailable) {
                    return AjaxResult.error("服务不存在");
                }
                return AjaxResult.error(throwable.getMessage());
            }
        };
    }
}
